﻿#include "viewwidget.h"
#include "ui_viewwidget.h"

ViewWidget::ViewWidget(QWidget *parent, bool hasDetailDialog)
    : QWidget(parent)
    , m_hasDetailDialog(hasDetailDialog)
    , ui(new Ui::ViewWidget)
    , m_viewBox(new CustomGraphicsView(this))
{
    ui->setupUi(this);
    ui->ViewBox_widget->layout()->addWidget(m_viewBox);

    m_viewBox->SetImage(QImage(":/image/noimage.jpg"));

    connect(m_viewBox,&CustomGraphicsView::select,this,&ViewWidget::HasSelected);
}

ViewWidget::~ViewWidget()
{
    delete ui;
    delete m_viewBox;
}

void ViewWidget::SetPositionInfoShow(bool bShow)
{
    m_viewBox->SetPositionInfoShow(bShow);
}

void ViewWidget::SetDefectInfoShow(bool bShow)
{
    m_viewBox->SetDefectInfoShow(bShow);
}

void ViewWidget::SetDetectionResult(SeatDetectionParameter &seatDetectionParameter,
                                    DetectionResult &detectionResult, bool isShow10X)
{
    if (detectionResult.GetInfo().GetFileName().toInt() == m_fileNumber || m_fileNumber == 0) {
        this->m_seatDetectionParameter = seatDetectionParameter;
        this->m_detectionResult = detectionResult;

        m_viewBox->SetDetectionResult(seatDetectionParameter, detectionResult,isShow10X);
    }
}

void ViewWidget::SetImage(QString path)
{
    m_viewBox->SetImage(path);
}

void ViewWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
    if (m_hasDetailDialog) {
        // 作为成员
        ImageDetailDialog *pImageDetailDialog = new ImageDetailDialog(this);
        pImageDetailDialog->showMaximized();
        pImageDetailDialog->setModal(true);
        pImageDetailDialog->show();

        pImageDetailDialog->SetDetectionResult(m_seatDetectionParameter, m_detectionResult);
    }
}

void ViewWidget::HasSelected(){
    emit changeSelect(m_fileNumber);
}

void ViewWidget::SetImage(QImage& image){
    m_viewBox->SetImage(image);
}
